package org.icue.service.client;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.restlet.Client;
import org.restlet.data.Form;
import org.restlet.data.Protocol;
import org.restlet.data.Response;

public class CueClient {
	/** Base application URI. */
	public static final String APPLICATION_URI = "http://10.1.130.244:3030/icue/v1";

	/**
	 * Main method to use for testing.
	 * 
	 * @param args
	 *            The arguments or nothing for a usage description.
	 * @throws Exception
	 */
	public static void main(String... args) throws Exception {
		putImage("imagename1", "/path/to/image", new Date(System
				.currentTimeMillis()), 654987);
	}

	public static String getImageURI(String name) {
		return APPLICATION_URI + "/images/" + name;
	}

	public static void putImage(String name, String path, Date timestamp,
			int size) {
		SimpleDateFormat sdf = new SimpleDateFormat();
		sdf.applyPattern("d/m/y h:m:s");
		System.out.println("Current Date : " + sdf.format(timestamp));
		Form form = new Form();
		form.add("image[name]", name);
		form.add("image[path]", path);
		form.add("image[timestamp]", sdf.format(timestamp));
		form.add("image[size]", ((Integer) size).toString());

		Response resp = new Client(Protocol.HTTP).put(getImageURI(name), form
				.getWebRepresentation());
		System.out.println("Réponse Serveur :");
		System.out.println(resp.getStatus());
	}
}
